<?php 
	set_time_limit(0);
	include_once("init.php");
	if (DEBUG) {
		error_reporting(E_ALL);
	} else {
		error_reporting(0);
	}
	if (!isset($_POST['q']) || empty($_POST['q'])) {
		echo json_encode(array('status'=>'error','info'=>'没有查询条件'));
		die();
	}

	$mongodb = OpenDB($CONFIG['MONGDB']);
	if (is_array($mongodb) && $mongodb['status']=='error') {
		//$str = $mongodb['info'];
		echo json_encode(array('status'=>'error','info'=>'连接数据库失败.'));
		die();
	}
	try {
		$sgk = $mongodb->selectDB($CONFIG['DB']);
		$tables = GetCollections($sgk);
	} catch (Except $e){
		echo json_encode(array('status'=>'error','info'=>$e->getMessage()));
		die();
	}


	$search['str'] = $_POST['q'];
	$search['type'] = 'eq';
	$search['field'] = 'username';
	$t1 = microtime(true);
	$data = GetData4Collections($sgk,$tables,$search);
	$t2 = microtime(true);
	$time = (($t2-$t1)*1000).'ms';
	echo json_encode(array('status'=>'ok','info'=>'','data'=>$data,'time'=>$time));
	CloseDB($mongodb);
?>
